set more off

*** read data ***

set more off

use "reassessments", clear

merge 1:1 swis_code year using "switchers"
keep if _m == 3
drop _m

merge m:m muni_name county_name year using "census demographics"
drop _m

merge m:m muni_name county_name year using "finances clean"
drop _m

merge m:m muni_name county_name year using "employment"
drop _m

merge m:m swis_code year using "salesweb"
keep if _m == 3
drop _m

*** recode for interpretation ***

gen elected = 1-D
su lprice
replace lprice = (lprice - r(min)) / (r(max) - r(min))
replace rar = rar * 100

*** controls ***

#delimit;

local X 
	lpopulation 
	lmedianincome 
	pct65plus 
	pctwhite 
	pctunemployed 
	pctrenter 
	pctagricuture
	ltotalrevenue
	pctptax
	surpluspcp
	totalftequivalent
	;

#delimit cr

*** do the regressions ***

gen electedXlprice = elected*lprice 

eststo clear

eststo: xi: areg rar lprice elected electedXlprice i.year `X', a(swis_code) cl(swis_code)
eststo: xi: areg rar lprice elected electedXlprice i.year `X' if year < 2007, a(swis_code) cl(swis_code)
eststo: xi: areg rar lprice elected electedXlprice i.year `X' if year >= 2007, a(swis_code) cl(swis_code)

label variable lprice "Sale price (log)"
label variable elected "Elected assessor"
label variable electedXlprice "Elected $\times$ price"

esttab, drop(*year*) se



#delimit;

esttab
	using "table A4.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(elected electedXlprice lprice)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Controls = lpopulation")
		stats(

			N
			,
				label(

					"Observations"
						
				)
				fmt(%20.0fc)
		)
		mgroups(
			"2003-2011" "< 2007" "$\geq$ 2007", pattern(1 1 1)               
			prefix(\multicolumn{@span}{c}{) suffix(})   
			span erepeat(\cmidrule(lr){@span})
		)
		;
	
#delimit cr

shell "tabler.sh" "table A4.tex" "Effective tax rate" "Property"
